package cn.cjxy.service;

import cn.cjxy.domain.User;
import cn.cjxy.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    //依赖注入mapper
    @Autowired
    private UserMapper userMapper;

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    public User findByUsername(String username) {
        User byUsername = userMapper.findByUsername(username);
        return byUsername;
    }

    /**
     * 查询所有用户
     * @return
     */
    public List<User> findAll(String username,String address) {
       return userMapper.findAll(username,address);
    }

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    public User findUserById(Integer id) {
        User user=userMapper.findUserById(id);
        return user;
    }

    /**
     * 修改用户
     * @param user
     */
    public void update(User user) {
        userMapper.update(user);
    }

    /**
     * 根据id删除
     * @param id
     */
    public void delete(Integer id) {
        userMapper.delete(id);
    }

    /**
     * 新增用户
     * @param user
     */
    public void save(User user) {
        userMapper.save(user);
    }
}
